package com.huida.app.hutoolsusage;

import cn.hutool.core.util.StrUtil;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @author wangzhuangzhuang
 * @DESC:
 * @date 2022-01-10 15:16
 */
@SpringBootTest
public class StrUtilUsageDemo {

	// 1. hasBlank、hasEmpty方法
	// - hasEmpty只判断是否为null或空字符串("")
	// - hasBlank 把不可见字符也算作为空
	@Test
	public void test01() {

	}

	// removePrefix、removeSuffix
	// 去掉字符串的前缀后缀的，列如去个文件名的扩展名
	@Test
	public void test02() {
		String fileName = StrUtil.removeSuffix("pretty_girl.jpg", ".jpg");
		System.out.println("fileName: " + fileName); // fileName: pretty_girl
	}

	// sub方法
	@Test
	public void test03() {
		String str = "abcdefgh";
		String strSub01 = StrUtil.sub(str, 2, 3);
		String strSub02 = StrUtil.sub(str, 2, -3);
		String strSub03 = StrUtil.sub(str, 3, 2);
		System.out.println("strSub01: " + strSub01 + " strSub02: " + strSub02 + " strSub03: " + strSub03);
		// strSub01: c strSub02: cde strSub03: c
	}

	// format方法
	@Test
	public void test04() {
		String template = "{}爱{}, 就像老鼠爱大米";
		String info01 = StrUtil.format(template, "A", "B");
		String info02 = StrUtil.format(template, "TestA", "TestB");
		System.out.println("info01: " + info01);
		System.out.println("info02: " + info02);
		/***
		 * info01: A爱B, 就像老鼠爱大米
		 * info02: TestA爱TestB, 就像老鼠爱大米
		 */
	}

	@Test
	public void test05() {

	}

}